﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

/// <summary>
/// RTypeService 的摘要说明
/// </summary>

namespace RType
{
    public class RTypeService
    {
        public RTypeService()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        DataBase data = new DataBase();
        #region 添加--读者类型信息
        /// <summary>
        /// 添加--读者类型信息
        /// </summary>
        /// <param name="rtypemanage"></param>
        /// <returns></returns>
        public int AddRType(RTypeManage rtypemanage)
        {
            SqlParameter[] prams = {
            data.MakeInParam("@name",  SqlDbType.VarChar, 50, rtypemanage.Name ),
            data.MakeInParam("@number",  SqlDbType.Int, 4,rtypemanage.Number ),
            };
            return (data.RunProc("INSERT INTO tb_readertype (name,number) VALUES(@name,@number)", prams));
        }
        #endregion

        #region 修改--读者类型信息
        /// <summary>
        /// 修改--读者类型信息
        /// </summary>
        /// <param name="rtypemanage"></param>
        /// <returns></returns>
        public int UpdateRType(RTypeManage rtypemanage)
        {
            SqlParameter[] prams = {
            data.MakeInParam("@id",  SqlDbType.Int, 4, rtypemanage.ID ),
            data.MakeInParam("@name",  SqlDbType.VarChar, 50, rtypemanage.Name ),
            data.MakeInParam("@number",  SqlDbType.Int, 4,rtypemanage.Number ),
            };
            return (data.RunProc("update tb_readertype set name=@name,number=@number where id=@id", prams));
        }
        #endregion

        #region 删除--读者类型信息
        /// <summary>
        /// 删除--读者类型信息
        /// </summary>
        /// <param name="rtypemanage"></param>
        /// <returns></returns>
        public int DeleteRType(RTypeManage rtypemanage)
        {
            SqlParameter[] prams = {
            data.MakeInParam("@id",  SqlDbType.Int, 4, rtypemanage.ID ),
            };
            return (data.RunProc("delete from tb_readertype where id=@id", prams));
        }
        #endregion

        #region 查询--读者类型信息
        /// <summary>
        /// 根据--读者类型--得到读者类型信息
        /// </summary>
        /// <param name="rtypemanage"></param>
        /// <param name="tbName"></param>
        /// <returns></returns>
        public DataSet FindRTypeByName(RTypeManage rtypemanage, string tbName)
        {
            SqlParameter[] prams = {
            data.MakeInParam("@name",  SqlDbType.VarChar, 50, rtypemanage.Name+"%"),
            };
            return (data.RunProcReturn("select * from tb_readertype where name like @name", prams, tbName));
        }
        /// <summary>
        /// 得到所有--读者类型信息
        /// </summary>
        /// <param name="tbName"></param>
        /// <returns></returns>
        public DataSet GetAllRType(string tbName)
        {
            return (data.RunProcReturn("select * from tb_readertype ORDER BY id", tbName));
        }
        #endregion
    }
}